<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03-对象></title>
</head>
<body>
    <script>
        // 使用Object创建对象
        var ob1 = new Object();
        ob1.name = "宝强";
        ob1.age = 18;
        ob1.show = function () {
          console.log(this.name + "--" + this.age);
        }
        // 调用成员
        console.log(ob1.name);
        console.log(ob1.age);
        ob1.show()

        // 第二种创建方法 采用赋值创建方法  推荐
        var obj2 = {
          name : "宝强",
          age : 18,
          show:function () {
            console.log(this.name + "--" + this.age)
          },
          eat:function () {
            console.log(this.name + "正在吃饭")
          }
        }
        // 调用方法
        console.log(obj2.name);
        console.log(obj2.age);
        obj2.eat();
        obj2.show();

        // 第三种创建方法 构造函数创建
        function Student(name , age){
          this.name = name;
          this.age = age;
          this.show = function () {
            console.log(this.name + "--" +this.age)
          }
        }

        var student = new Student("宝强",18);
        console.log(student);
        student.show()
    </script>
</body>
</html>